function previewImage(){
    var fileReader = new FileReader();
    fileReader.readAsDataURL(document.form.file.files[0]);
    fileReader.onload = function (oFREvent) {
        document.getElementById("image_post").src = oFREvent.target.result;
    };
}
function Username() {
    var emailRegex = /^[A-Za-z0-9._]*\@[A-Za-z]*\.[A-Za-z]{2,5}$/;
    var uname = document.form.userName.value;
    if (uname == "") {
        document.form.userName.focus();
        document.getElementById("errorBox").innerHTML = "enter the Username";
        return false;
    }
    document.getElementById("errorBox").innerHTML = "";
    return true;

}
function Password() {
    var emailRegex = /^[A-Za-z0-9._]*\@[A-Za-z]*\.[A-Za-z]{2,5}$/;
    var pass = document.form.pwd.value;
    if (pass == "") {
        document.form.pwd.focus();
        document.getElementById("errorBox").innerHTML = "enter the Password";
        return false;
    }
    if (pass.length < 6) {
        document.form.pwd.focus();
        document.getElementById("errorBox").innerHTML = "Password lenght more 6 chactor";
        return false;
    }
    document.getElementById("errorBox").innerHTML = "";
    return true;
}
function Confim_password() {

    var conf_pass = document.form.re_pwd.value;
    var pass = document.form.pwd.value;
    if (conf_pass !== pass)
    {
        document.form.userName.focus();
        document.getElementById("errorBox").innerHTML = "Error:Confirm must be equal to password.";
        return false;
    }
    document.getElementById("errorBox").innerHTML = "";
    return true;
}
function Fullname() {
    var fname = document.form.fullName.value;
    if (fname == "") {
        document.form.userName.focus();
        document.getElementById("errorBox").innerHTML = "Enter the FullName";
        return false;
    }
    document.getElementById("errorBox").innerHTML = "";
    return  true;
}

function Idcard() {
    var tell = /^[0-9]/g;
    var idcard = document.form.idCard.value;
    if (idcard == "") {
        document.form.userName.focus();
        document.getElementById("errorBox").innerHTML = "Enter the IdCard";
        return false;
    }
    if (tell.test(idcard) == false) {
        document.form.userName.focus();
        document.getElementById("errorBox").innerHTML = "Please insert number";
        return false;
    }
    if (idcard.length !== 10) {
        document.form.userName.focus();
        document.getElementById("errorBox").innerHTML = "err";
        return false;
    }
    document.getElementById("errorBox").innerHTML = "";
    return true;

}

function Email() {
    var emailRegex = /^[A-Za-z0-9._]*\@[A-Za-z]*\.[A-Za-z]{2,5}$/;
    var email = document.form.email.value;
    if (email == "") {
        document.form.email.focus();
        document.getElementById("errorBox").innerHTML = "Enter the Email";
        return false;
    }
    if (emailRegex.test(email) == false) {
        document.form.email.focus();
        document.getElementById("errorBox").innerHTML = "Please enter a valid email address";
        return false;
    }
    document.getElementById("errorBox").innerHTML = "";
    return true;
}
function Address() {
    var address = document.form.address.value;
    if (address == "") {
        document.form.email.focus();
        document.getElementById("errorBox").innerHTML = "Enter the Address";
        return false;
    }
    document.getElementById("errorBox").innerHTML = "";
    return true;

}
function Phone() {
    var tell = /^[0-9]/g;
    var phone_number = document.form.phone.value;
    if (phone_number == "") {
        document.form.phone.focus();
        document.getElementById("errorBox").innerHTML = "Enter the Phone ";
        return false;
    }
    if (tell.test(phone_number) == false) {
        document.form.phone.focus();
        document.getElementById("errorBox").innerHTML = "Please insert number";
        return false;
    }
    document.getElementById("errorBox").innerHTML = "";
    return true;
}
function agree() {
    if (document.form.commit.checked) {
        document.getElementById("errorBox").innerHTML = "";
        return true;

    } else
    {
        document.getElementById("errorBox").innerHTML = "Please check agree";
        return false;
    }
}

function Phone() {

    var tell = /^[0-9]/g;
    var phone_number = document.form.phone.value;
    if (phone_number == "") {
        document.form.phone.focus();
        document.getElementById("errorBox").innerHTML = "Enter the Phone ";
        return false;
    }
    if (tell.test(phone_number) == false) {
        document.form.phone.focus();
        document.getElementById("errorBox").innerHTML = "Please insert number";
        return false;
    }
    document.getElementById("errorBox").innerHTML = "";
    return true;
}
function confirmDelete(){
   return confirm("Are you sure! You want delete?");
}
function changeOffset() {
    document.formOffset.submit();
}
function selectAll() {
    var cbRoot = document.getElementById("cb_root");
    var arrSub = document.getElementsByClassName("cb_sub");
    for (i = 0; i < arrSub.length; i++)
        arrSub[i].checked = cbRoot.checked;
}
function selectItem(form){
    var cbRoot = document.getElementById("cb_root");
    if(form.checked == false)
        cbRoot.checked = false;
}